﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using personalplaner.business.dienstplan;
using personalplaner.common.controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace personalplaner.common.controls.documents
{
    /// <summary>
    /// document class that is used to print content from <see cref="PrintPreviewItemsControl"/>
    /// </summary>
	internal class PrintDocumentPaginator : DocumentPaginator
	{
		readonly PrintPreviewItemsControl printControl;

		public PrintDocumentPaginator(PrintPreviewItemsControl printControl)
		{
			this.printControl = printControl;
		}

		public override DocumentPage GetPage(int pageNumber)
		{
			if (!printControl.SelectPage(pageNumber))
				return null;

            // version 1
            printControl.SelectedContentPresenter.UpdateLayout();
            return new DocumentPage(printControl.SelectedContentPresenter);
            

            // vresion 2

            //var page = printControl.SelectedContentPresenter;

            ////var visual = new DrawingVisual();
            ////using (DrawingContext dc = visual.RenderOpen())
            ////{
            ////    dc.draw
            ////}

            //var visual = new ContainerVisual();
            //visual.Children.Add(page.Content as FrameworkElement);

            //return new DocumentPage(visual);
		}

		public override bool IsPageCountValid
		{
			get { return true; }
		}

		public override int PageCount
		{
			get
			{
				return printControl.Items != null ? printControl.Items.Count : 0;
			}
		}

		public override Size PageSize
		{
			get
			{
				var tmp = printControl.SelectedContentPresenter;
				if (tmp != null)
					return new Size(tmp.ActualWidth, tmp.ActualHeight);
				return new Size();
			}
			set
			{
			}
		}

		public override IDocumentPaginatorSource Source
		{
			get
			{
				// ??? what is expected here ???
				return null;
			}
		}
	}
}
